#ifndef VObjectTView_First
#define VObjectTView_First
#ifdef __GNUG__
#pragma interface
#endif

#include "TextView.h"
#include "TextCmd.h"
#include "CompVObject.h"

class VObjectText;

//---- VObjectTextView ---------------------------------------------------------

class VObjectTextView: public TextView {
public:
	MetaDef(VObjectTextView);

	VObjectTextView(EvtHandler *eh, const Rectangle &r, VObjectText *t,
		bool wrap= TRUE, TextViewFlags= eTextViewDefault, const Point &border= gBorder,
		TViewAlign m= eTViewLeft, int id= cIdNone);
	~VObjectTextView();

	//---- overriden to update VObjects
	void SetOrigin(Point);

	void Control(int id, int part, void *val);
	Text *SetText(Text *newText, bool scroll= cRevealTop);

	//---- extended for pasting VObjects
	Command *PasteData(Data *data);
	void PasteVObject(VObject *vop);
	void PasteVisualMark(VisualMark *vmp);

	//---- distribute input events to embedded graphic objects
	Command *DispatchEvents(Point lp, Token &t, Clipper*);
	VisualMark *IsInputForVisualMark(Point p);

	GrCursor GetCursor(Point);
	IStream& ReadFrom(IStream&);
};

//---- PasteVObjectCommand -----------------------------------------------------

class PasteVObjectCommand: public TextCommand {
protected:
	VObjectTextView *vtv;
	VisualMark *vmp;
	VObjectText *vt;
	int newStart, newEnd;
public:
	MetaDef(PasteVObjectCommand);
	PasteVObjectCommand(VObjectTextView*, VObject*, int cmdNo= cPASTE, char *cmdName= 0);
	PasteVObjectCommand(VObjectTextView*, VisualMark*, int cmdNo= cPASTE, char *cmdName= 0);
	~PasteVObjectCommand();
	void DoIt();
	void UndoIt();
	void RedoIt();
};

//---- StretchWrapper ----------------------------------------------------------
//     a VObject installed in a StretchWrapper and inserted in a
//     VObjectText can be resized interactively

class StretchWrapper: public CompositeVObject {
protected:
	Point interiorOffset, extentDiff, border;
	VObject *interior;
public:
	MetaDef(StretchWrapper);

	StretchWrapper(VObject *inner, const Point &border, int= cIdNone);
	VObject *GetInterior()
		{ return interior; }
	Point GetInteriorOffset()
		{ return interiorOffset; }
	void SetOrigin(Point at);
	void SetExtent(Point e);
	Metric GetMinSize();
	Command *DoLeftButtonDownCommand(Point, Token, int);
	Command *DoKeyCommand(int ch, Token t);
	void Control(int id, int part, void *val);
	void SendDown(int id, int part, void *val);
	GrCursor GetCursor(Point);
	OStream &PrintOn(OStream&);
	IStream &ReadFrom(IStream&);
	void Draw(Rectangle);
	bool KbdFocus(bool in);
};

#endif
